package LeetCode.exercise;

public class LC1004 {
    public static int longestOnes(int[] nums, int k) {
        int left = 0, right = 0, zero = 0;
        int res = 0;
        for(; right < nums.length; right++){
            if(nums[right] == 0){
                zero++;
            }
            while(zero > k){
                if(nums[left++] == 0){
                    zero--;
                }
            }
            res = Math.max(res, right-left+1);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(longestOnes(new int[]{1,1,1,0,0,0,1,1,1,1}, 0));
        System.out.println(longestOnes(new int[]{0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1}, 3));
    }
}
